#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
typedef long long ll;
const int N = 35;
int t, n;
int main() {
    cin >> t;
    while (t--) {
        cin >> n;
        vector<ll> a(2 * n);
        for (int i = 0; i < 2 * n; i++){
        	cin >> a[i];
		}
		long long ans = 0;
		for (int i = 35; i >= 0; i--){
			ll k = ans | (1ll << i);
			int cnt = 0;
			for (int j = 0; j < 2 * n; j++){
				if ((k & a[j]) == k) cnt++;
			}
			if (cnt >= n) ans = k;
		}
		cout << ans << endl;
    }
    return 0;
}
